package com.gxa.wmcrm.service.Impl;

import com.gxa.wmcrm.entity.Department;
import com.gxa.wmcrm.service.DepartmentByService;
import com.gxa.wmcrm.service.DepartmentByService;
import com.gxa.wmcrm.util.DBUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class DepartmentByImpl implements DepartmentByService{
    PreparedStatement ps = null;
    ResultSet rs = null;
    Connection conn = null;
    @Override
    public List<Department> byDepartment(String st) {
        List<Department> list = null;
        try {
            // 调用工具类DBUtil，初始化数据库驱动，创建数据库连接
            Connection conn = DBUtil.getConn();
            String sql = "select *  from  department where depotName like ?";
            ps = conn.prepareStatement(sql);
            String s = "%"+st+"%";
            ps.setString(1,s);
            rs = ps.executeQuery();
            list = new ArrayList<Department>();
            while(rs.next()){
                Department d = new Department();
                d.setDepotId(rs.getInt("depotId"));
                d.setDepotName(rs.getString("depotName"));
                d.setDepotSetTime(rs.getDate("depotSetTime"));
                d.setDepotDescribe(rs.getString("depotDescribe"));
                list.add(d);
            }
        } catch (SQLException e) {
            e.getStackTrace();
        } finally {
            DBUtil.closeConn(conn, ps, null);
        }
        return list;
    }
}
